package cn.springboot.erp.controller;

import cn.springboot.erp.commons.QueryParams;
import cn.springboot.erp.commons.ResponseResult;
import cn.springboot.erp.entity.Inventory;
import cn.springboot.erp.service.InventoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("inventory")
@Api(tags = "库存管理")
public class InventoryController {

    @Resource
    private InventoryService inventoryService;

    @ApiOperation("数据分页")
    @PostMapping("page")
    public ResponseResult listPage(@RequestBody QueryParams<Inventory> queryParams){
        return inventoryService.listPage(queryParams);
    }

    @ApiOperation("添加数据")
    @PostMapping("insert")
    public ResponseResult insert(@RequestBody Inventory inventory){
        inventoryService.save(inventory);
        return ResponseResult.Success().msg("添加成功");
    }

    @ApiOperation("根据id删除")
    @GetMapping("deleteById/{id}")
    public ResponseResult deleteById(@PathVariable("id") Integer id){
        inventoryService.removeById(id);
        return ResponseResult.Success().msg("删除成功");
    }
}
